package com.customview.CustomArc;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;

import com.customview.R;


/**
 * Created by Administrator on 2017/7/13.
 */

public class CustomArc extends View {

    //默认的弧度 120
    float mAnagle=120;
    //默认弧的宽度
    float  mStrok;
    //颜色
    int mColor;

    Paint mPaint;
    public CustomArc(Context context) {
        this(context,null);
    }

    public CustomArc(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public CustomArc(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CustomArc, defStyleAttr, 0);


        //获取属性

        mAnagle=  typedArray.getDimension(R.styleable.CustomArc_mangle, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,15,getResources().getDisplayMetrics()));

        mStrok =typedArray.getDimension(R.styleable.CustomArc_mStrok,TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,15,getResources().getDisplayMetrics()));

      //  mColor =typedArray.getColor(R.styleable.CustomArc_mColor, Color.BLUE);


        //回收
        typedArray.recycle();


        mPaint=new Paint();
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(mStrok);
        mPaint.setColor(mColor);


    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
       setMeasuredDimension(getDefaultSize(getSuggestedMinimumWidth(),widthMeasureSpec),getDefaultSize(getSuggestedMinimumHeight(),heightMeasureSpec));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);


        int measuredHeight = getMeasuredHeight();
        int measuredWidth = getMeasuredWidth();

        RectF f =new RectF(0,0,measuredWidth,measuredHeight);

        canvas.drawArc(f,200,mAnagle,true,mPaint);


    }
}
